<#-- 包路径 -->
<#if package??>
package ${package.Controller};

<#else>
package com.example.controller;
</#if>

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

<#-- 导入 Service -->


@RestController
@RequestMapping("/${entity?replace('Model', '')?lower_case}")
public class ${table.controllerName} {

    @Autowired
    private ${table.serviceName} ${table.serviceName?uncap_first};


    /**
     * 查询所有记录
     */
    @GetMapping("/selectAll")
    public List<${entity}> selectAll() {
        return ${table.serviceName?uncap_first}.list();
    }

    /**
     * 根据 ID 查询记录
     */
    @GetMapping("/{id}")
    public ${entity} getById(@PathVariable Long id) {
        return ${table.serviceName?uncap_first}.getById(id);
    }

    /**
     * 创建新记录
     */
    @PostMapping("/insert")
    public boolean insert(${entity} ${entity?uncap_first}) {
      return ${table.serviceName?uncap_first}.save(${entity?uncap_first});
    }

    /**
     * 更新记录
     */
    @PutMapping("/{id}")
    public boolean updateById(${entity} ${entity?uncap_first}) {
        return ${table.serviceName?uncap_first}.updateById(${entity?uncap_first});
    }

    /**
     * 删除记录
     */
    @DeleteMapping("/{id}")
    public boolean delete(@PathVariable Long id) {
        return ${table.serviceName?uncap_first}.removeById(id);
    }
}
